<template>
  <div id="mod-config">
    <el-form :inline="true" :model="dataForm2" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm2.key" placeholder="参数名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button  type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
            :data="dataList"
            border
            v-loading="dataListLoading"
            @selection-change="selectionChangeHandle"
            style="width: 100%;">
      <el-table-column
              type="selection"
              header-align="center"
              align="center"
              width="50">
      </el-table-column>
              <el-table-column
                prop="id"
                header-align="center"
                align="center"
                label="序号">
        </el-table-column>
              <el-table-column
                prop="orderNum"
                header-align="center"
                align="center"
                label="订单编号">
        </el-table-column>
              <el-table-column
                prop="userId"
                header-align="center"
                align="center"
                label="用户id">
        </el-table-column>
              <el-table-column
                prop="goodId"
                header-align="center"
                align="center"
                label="商品id">
        </el-table-column>
              <el-table-column
                prop="goodQuantity"
                header-align="center"
                align="center"
                label="商品数量">
        </el-table-column>
              <el-table-column
                prop="aggregateAmount"
                header-align="center"
                align="center"
                label="总金额">
        </el-table-column>
              <el-table-column
                prop="actuallyPaid"
                header-align="center"
                align="center"
                label="实际支付">
        </el-table-column>
              <el-table-column
                prop="createTime"
                header-align="center"
                align="center"
                label="下单时间">
        </el-table-column>
              <el-table-column
                prop="orderStatus"
                header-align="center"
                align="center"
                label="订单状态(1等待付款 2申请退款 3退款成功 4交易成功)">
        </el-table-column>
              <el-table-column
                prop="payStatus"
                header-align="center"
                align="center"
                label="支付状态(1已支付 2未支付)">
        </el-table-column>
              <el-table-column
                prop="shippingStatus"
                header-align="center"
                align="center"
                label="发货状态(1未发货 2已发货)">
        </el-table-column>
              <el-table-column
                prop="receivingAForm"
                header-align="center"
                align="center"
                label="收货状态(1未收货 2已收货)">
        </el-table-column>
              <el-table-column
                prop="remarkDesc"
                header-align="center"
                align="center"
                label="发货备注">
        </el-table-column>
              <el-table-column
                prop="logisticsInformationId"
                header-align="center"
                align="center"
                label="快递单号">
        </el-table-column>
              <el-table-column
                prop="logisticsInformation"
                header-align="center"
                align="center"
                label="物流公司">
        </el-table-column>
              <el-table-column
                prop="
exemptionFromPostageStatus"
                header-align="center"
                align="center"
                label="">
        </el-table-column>
              <el-table-column
                prop="a"
                header-align="center"
                align="center"
                label="">
        </el-table-column>
              <el-table-column
                prop="b"
                header-align="center"
                align="center"
                label="">
        </el-table-column>
              <el-table-column
                prop="c"
                header-align="center"
                align="center"
                label="">
        </el-table-column>
            <el-table-column
              fixed="right"
              header-align="center"
              align="center"
              width="150"
              label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
                                                <el-form-item label="订单编号" prop="orderNum">
              <el-input v-model="dataForm.orderNum" placeholder="订单编号"></el-input>
            </el-form-item>
                                        <el-form-item label="用户id" prop="userId">
              <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
            </el-form-item>
                                        <el-form-item label="商品id" prop="goodId">
              <el-input v-model="dataForm.goodId" placeholder="商品id"></el-input>
            </el-form-item>
                                        <el-form-item label="商品数量" prop="goodQuantity">
              <el-input v-model="dataForm.goodQuantity" placeholder="商品数量"></el-input>
            </el-form-item>
                                        <el-form-item label="总金额" prop="aggregateAmount">
              <el-input v-model="dataForm.aggregateAmount" placeholder="总金额"></el-input>
            </el-form-item>
                                        <el-form-item label="实际支付" prop="actuallyPaid">
              <el-input v-model="dataForm.actuallyPaid" placeholder="实际支付"></el-input>
            </el-form-item>
                                        <el-form-item label="下单时间" prop="createTime">
              <el-input v-model="dataForm.createTime" placeholder="下单时间"></el-input>
            </el-form-item>
                                        <el-form-item label="订单状态(1等待付款 2申请退款 3退款成功 4交易成功)" prop="orderStatus">
              <el-input v-model="dataForm.orderStatus" placeholder="订单状态(1等待付款 2申请退款 3退款成功 4交易成功)"></el-input>
            </el-form-item>
                                        <el-form-item label="支付状态(1已支付 2未支付)" prop="payStatus">
              <el-input v-model="dataForm.payStatus" placeholder="支付状态(1已支付 2未支付)"></el-input>
            </el-form-item>
                                        <el-form-item label="发货状态(1未发货 2已发货)" prop="shippingStatus">
              <el-input v-model="dataForm.shippingStatus" placeholder="发货状态(1未发货 2已发货)"></el-input>
            </el-form-item>
                                        <el-form-item label="收货状态(1未收货 2已收货)" prop="receivingAForm">
              <el-input v-model="dataForm.receivingAForm" placeholder="收货状态(1未收货 2已收货)"></el-input>
            </el-form-item>
                                        <el-form-item label="发货备注" prop="remarkDesc">
              <el-input v-model="dataForm.remarkDesc" placeholder="发货备注"></el-input>
            </el-form-item>
                                        <el-form-item label="快递单号" prop="logisticsInformationId">
              <el-input v-model="dataForm.logisticsInformationId" placeholder="快递单号"></el-input>
            </el-form-item>
                                        <el-form-item label="物流公司" prop="logisticsInformation">
              <el-input v-model="dataForm.logisticsInformation" placeholder="物流公司"></el-input>
            </el-form-item>
                                        <el-form-item label="" prop="
exemptionFromPostageStatus">
              <el-input v-model="dataForm.
exemptionFromPostageStatus" placeholder=""></el-input>
            </el-form-item>
                                        <el-form-item label="" prop="a">
              <el-input v-model="dataForm.a" placeholder=""></el-input>
            </el-form-item>
                                        <el-form-item label="" prop="b">
              <el-input v-model="dataForm.b" placeholder=""></el-input>
            </el-form-item>
                                        <el-form-item label="" prop="c">
              <el-input v-model="dataForm.c" placeholder=""></el-input>
            </el-form-item>
                        </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
 new Vue({
    el: '#mod-config',
    data () {
      return {

        baseURL: 'http://localhost:7001',
        dataForm2: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        visible: false,
        dataForm: {
                                      id: 0,
                                                  orderNum: '',
                                                  userId: '',
                                                  goodId: '',
                                                  goodQuantity: '',
                                                  aggregateAmount: '',
                                                  actuallyPaid: '',
                                                  createTime: '',
                                                  orderStatus: '',
                                                  payStatus: '',
                                                  shippingStatus: '',
                                                  receivingAForm: '',
                                                  remarkDesc: '',
                                                  logisticsInformationId: '',
                                                  logisticsInformation: '',
                                                  
exemptionFromPostageStatus: '',
                                                  a: '',
                                                  b: '',
                                                  c: ''
                              },
        dataRule: {
                                                            orderNum: [
                { required: true, message: '订单编号不能为空', trigger: 'blur' }
              ],
                                                  userId: [
                { required: true, message: '用户id不能为空', trigger: 'blur' }
              ],
                                                  goodId: [
                { required: true, message: '商品id不能为空', trigger: 'blur' }
              ],
                                                  goodQuantity: [
                { required: true, message: '商品数量不能为空', trigger: 'blur' }
              ],
                                                  aggregateAmount: [
                { required: true, message: '总金额不能为空', trigger: 'blur' }
              ],
                                                  actuallyPaid: [
                { required: true, message: '实际支付不能为空', trigger: 'blur' }
              ],
                                                  createTime: [
                { required: true, message: '下单时间不能为空', trigger: 'blur' }
              ],
                                                  orderStatus: [
                { required: true, message: '订单状态(1等待付款 2申请退款 3退款成功 4交易成功)不能为空', trigger: 'blur' }
              ],
                                                  payStatus: [
                { required: true, message: '支付状态(1已支付 2未支付)不能为空', trigger: 'blur' }
              ],
                                                  shippingStatus: [
                { required: true, message: '发货状态(1未发货 2已发货)不能为空', trigger: 'blur' }
              ],
                                                  receivingAForm: [
                { required: true, message: '收货状态(1未收货 2已收货)不能为空', trigger: 'blur' }
              ],
                                                  remarkDesc: [
                { required: true, message: '发货备注不能为空', trigger: 'blur' }
              ],
                                                  logisticsInformationId: [
                { required: true, message: '快递单号不能为空', trigger: 'blur' }
              ],
                                                  logisticsInformation: [
                { required: true, message: '物流公司不能为空', trigger: 'blur' }
              ],
                                                  
exemptionFromPostageStatus: [
                { required: true, message: '不能为空', trigger: 'blur' }
              ],
                                                  a: [
                { required: true, message: '不能为空', trigger: 'blur' }
              ],
                                                  b: [
                { required: true, message: '不能为空', trigger: 'blur' }
              ],
                                                  c: [
                { required: true, message: '不能为空', trigger: 'blur' }
              ]
                              }
      }
    },
    created () {
      this.getDataList()
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            axios({
              url: `${this.baseURL}/hospital_goods/orderlist/info/${this.dataForm.id}`,
              method: 'get',
            params: '',
                    // `responseType` 表示浏览器将要响应的数据类型
                    // 选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream'
                    responseType: 'json'
          }).then(({data}) => {
              if (data && data.code === 0) {
                                                                                this.dataForm.orderNum = data.orderList.orderNum
                                                                this.dataForm.userId = data.orderList.userId
                                                                this.dataForm.goodId = data.orderList.goodId
                                                                this.dataForm.goodQuantity = data.orderList.goodQuantity
                                                                this.dataForm.aggregateAmount = data.orderList.aggregateAmount
                                                                this.dataForm.actuallyPaid = data.orderList.actuallyPaid
                                                                this.dataForm.createTime = data.orderList.createTime
                                                                this.dataForm.orderStatus = data.orderList.orderStatus
                                                                this.dataForm.payStatus = data.orderList.payStatus
                                                                this.dataForm.shippingStatus = data.orderList.shippingStatus
                                                                this.dataForm.receivingAForm = data.orderList.receivingAForm
                                                                this.dataForm.remarkDesc = data.orderList.remarkDesc
                                                                this.dataForm.logisticsInformationId = data.orderList.logisticsInformationId
                                                                this.dataForm.logisticsInformation = data.orderList.logisticsInformation
                                                                this.dataForm.
exemptionFromPostageStatus = data.orderList.
exemptionFromPostageStatus
                                                                this.dataForm.a = data.orderList.a
                                                                this.dataForm.b = data.orderList.b
                                                                this.dataForm.c = data.orderList.c
                                              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
                if (valid) {
          axios({
            url: `${this.baseURL}/hospital_goods/orderlist/${!this.dataForm.id ? 'save' : 'update'}`,
            method: 'post',
          data: {
                                    'id': this.dataForm.id || undefined,
                                                        'orderNum': this.dataForm.orderNum,
                                                'userId': this.dataForm.userId,
                                                'goodId': this.dataForm.goodId,
                                                'goodQuantity': this.dataForm.goodQuantity,
                                                'aggregateAmount': this.dataForm.aggregateAmount,
                                                'actuallyPaid': this.dataForm.actuallyPaid,
                                                'createTime': this.dataForm.createTime,
                                                'orderStatus': this.dataForm.orderStatus,
                                                'payStatus': this.dataForm.payStatus,
                                                'shippingStatus': this.dataForm.shippingStatus,
                                                'receivingAForm': this.dataForm.receivingAForm,
                                                'remarkDesc': this.dataForm.remarkDesc,
                                                'logisticsInformationId': this.dataForm.logisticsInformationId,
                                                'logisticsInformation': this.dataForm.logisticsInformation,
                                                '
exemptionFromPostageStatus': this.dataForm.
exemptionFromPostageStatus,
                                                'a': this.dataForm.a,
                                                'b': this.dataForm.b,
                                                'c': this.dataForm.c
                                  },
          // `responseType` 表示浏览器将要响应的数据类型
          // 选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream'
          responseType: 'json'
        }).then(({data}) => {
            if (data && data.code === 0) {
			this.getDataList()
              this.$message({
                      message: '操作成功',
                      type: 'success',
                      duration: 1500,
                      onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
        })
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        axios({
          url:  `${this.baseURL}/hospital_goods/orderlist/list`,
          method: 'get',
        params: {
                'page': this.pageIndex,
                'limit': this.pageSize,
                'key': this.dataForm2.key
        },
        // `responseType` 表示浏览器将要响应的数据类型
        // 选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream'
        responseType: 'json'
      }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
this.init(id)
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
      }).then(() => {
          axios({
            url: `${this.baseURL}/hospital_goods/orderlist/delete`,
            method: 'post',
            data: ids,
            // `responseType` 表示浏览器将要响应的数据类型
            // 选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream'
            responseType: 'json'
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                      message: '操作成功',
                      type: 'success',
                      duration: 1500,
                      onClose: () => {
                this.getDataList()
              }
            })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  })
</script>
